﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Configuration;

namespace FileSynchronizer
{
    public partial class SettingsView : Form
    {
        public SettingsView()
        {
            InitializeComponent();
            localFoldertextBox.Text = SyncAgent.Instance.LocalFolder;
            remoteFoldertextBox.Text = SyncAgent.Instance.RemoteFolder;
        }

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            try
            {
                SyncAgent.Instance.LocalFolder = localFoldertextBox.Text;
                SyncAgent.Instance.RemoteFolder = remoteFoldertextBox.Text;
                this.DialogResult = DialogResult.OK;
            }
            catch (ConfigurationErrorsException ex)
            {
                MessageBox.Show(ex.Message);
                this.DialogResult = DialogResult.Abort;
            }
            finally
            {
                this.Close();
            }
        }

        private void selectLocalBtn_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                localFoldertextBox.Text = folderBrowserDialog.SelectedPath;
            }
        }

        private void selectRemoteBtn_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                remoteFoldertextBox.Text = folderBrowserDialog.SelectedPath;
            }

        }
    }
}
